package com.google.shop.product.controller.order;

import com.google.shop.product.common.utils.JwtUtils;
import com.google.shop.product.common.utils.MR;
import com.google.shop.product.common.utils.R;
import com.google.shop.product.repository.order.OrderRepository;
import com.google.shop.product.service.order.OrderService;
import com.google.shop.product.vo.order.savelineskuvo.LineSkuVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/order"})
@RestController
/* loaded from: app.jar:BOOT-INF/classes/com/google/shop/product/controller/order/OrderController.class */
public class OrderController {
    private static final Logger log = LoggerFactory.getLogger(OrderController.class);
    @Autowired
    OrderService orderService;
    @Autowired
    OrderRepository orderRepository;

    @GetMapping({"/buy"})
    public R buy(String token, Integer addressId) {
        if (token == null) {
            return R.error("token为空");
        }
        JwtUtils.getMemberIdByJwtToken(token);
        this.orderService.buy(token, addressId);
        return R.ok();
    }

    @GetMapping({"/list"})
    public R list(String token) {
        if (token == null) {
            return R.error("token为空");
        }
        String buyerId = JwtUtils.getMemberIdByJwtToken(token);
        System.out.println(buyerId);
        return R.ok(this.orderService.list(buyerId, token));
    }

    @PostMapping({"/saveLineSku"})
    public MR saveLineSku(@RequestBody LineSkuVO lineSkuVO) {
        if (lineSkuVO.getToken() == null) {
            return MR.error("token为空");
        }
        this.orderService.saveLineSku(lineSkuVO, JwtUtils.getMemberIdByJwtToken(lineSkuVO.getToken()));
        return MR.ok("购买成功");
    }
}
